<template>
  <div class="reportFormPage">
    <div class="report-dom">
      <el-row>
        <el-col :span="5" :offset="19">
          <div class="pageNumBox">
            <span>第</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.page }}&nbsp;</span>
            <span>页，共</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.totalPage }}&nbsp;</span>
            <span>页</span>
          </div>
        </el-col>
      </el-row>
      <div class="topTwoBox">
        <div class="centerName">钢材机械连接接头试验检测报告</div>
        <div class="codeText">BGLQ15006F</div>
      </div>
      <div class="threeTopBox">
        <div class="left-border">
          <div class="box-title">检测单位名称：</div>
          <div class>{{ form.jiancdwmc }}</div>
        </div>
        <div class="right-border">
          <span>报告编号：</span>
          <span v-if="isPdf" class="placeholder">{{ form.baogbh }}</span>
          <el-input class="code-input" v-else type="text" v-model="form.baogbh" @focus="handleFocus('baogbh')" />
        </div>
      </div>
      <div class="table-border">
        <!------------------------------表头-------------------------->
        <table height="220px" class="top-table">
          <tbody>
            <tr>
              <td height="30" align="center" width="15%">
                <span style="width: 90px; display: inline-block">施工/委托单位</span>
              </td>
              <td width="35%" bgcolor="#ffffff">
                <span>{{ form.shigwtdw }}</span>
              </td>
              <td align="center" width="15%">
                <span style="width: 90px; display: inline-block">工程名称</span>
              </td>
              <td bgcolor="#ffffff" width="35%">
                <span>{{ form.gongcmc }}</span>
              </td>
            </tr>
            <tr>
              <td height="30" align="center" width="15%">
                <span style="width: 90px; display: inline-block">工程部位/用途</span>
              </td>
              <td colspan="3">
                <span>{{ form.gongcbwyt }}</span>
              </td>
            </tr>
            <tr>
              <td height="50" align="center">样品信息</td>
              <td class="specimen-border" colspan="3">
                <span>样品名称：</span>
                <span :class="{ 'placeholder':!form.yangpmc }">{{ form.yangpmc }}</span>
                <span>；样品编号：</span>
                <span :class="{ 'placeholder-long':!form.yangpbh }">{{ form.yangpbh }}</span>
                <span>；样品数量：</span>
                <span :class="{ 'placeholder':!form.yangpsl }">{{ form.yangpsl }}</span>
                <span>；样品状态：</span>
                <span :class="{ 'placeholder':!form.yangpzt }">{{ form.yangpzt }}</span>
                <span>；来样时间：</span>
                <span :class="{ 'placeholder':!form.yangpsj }">{{ form.yangpsj }}</span>
              </td>
            </tr>
            <tr>
              <td height="50" align="center" width="15%">
                <span style="width: 90px; display: inline-block">检测依据</span>
              </td>
              <td width="35%">
                <span v-if="isPdf">{{ form.jiancyj }}</span>
                <el-input v-else type="textarea" v-model="form.jiancyj" :rows="2" class="mark" @dblclick.native="showBsJiancyjView" readonly />
              </td>
              <td align="center" width="15%">
                <span style="width: 90px; display: inline-block">判定依据</span>
              </td>
              <td width="35%">
                <span v-if="isPdf">{{ form.pandyj }}</span>
                <el-input v-else type="textarea" v-model="form.pandyj" :rows="2" @dblclick.native="showBsJudgeBaseView" @focus="handleFocus('pandyj')" class="mark" />
              </td>
            </tr>
            <tr class="bottom-border">
              <td height="50" align="center">
                <div>主要仪器设备</div>
                <div>名称及编号</div>
              </td>
              <td colspan="3">
                <span v-if="isPdf">{{ form.zhuyyqsbmcjbh }}</span>
                <el-input v-else type="textarea" :rows="2" v-model="form.zhuyyqsbmcjbh" class="height100 width100 mark" @dblclick.native="showBsInstrumentView" readonly></el-input>
              </td>
            </tr>
          </tbody>
        </table>
        <!------------------------------表中-------------------------->
        <table height="616px" class="middle-table">
          <tbody>
            <tr height="25">
              <td>生产厂家</td>
              <td colspan="2"><el-input type="text" v-model="form.cd" /></td>
              <td>代表数量</td>
              <td colspan="4"><el-input type="text" v-model="form.daibsl" /></td>
            </tr>
            <tr height="25">
              <td>进场日期</td>
              <td colspan="2"><el-input type="text" v-model="form.jincrq" /></td>
              <td>批号</td>
              <td colspan="4"><el-input type="text" v-model="form.pih" /></td>
            </tr>
            <tr height="25">
              <td colspan="2">钢筋强度等级牌号</td>
              <td><el-input type="text" v-model="form.gangjqddjph" /></td>
              <td>连接形势</td>
              <td colspan="4"><el-input type="text" v-model="form.lianjxs" /></td>
            </tr>
            <tr height="60">
              <td width="15%">试件编号</td>
              <td width="15%">钢筋直径(mm)</td>
              <td width="15%">钢筋截面积(mm²)</td>
              <td width="15%">技术指标</td>
              <td width="10%">连接件抗拉强度实测值(MPa)</td>
              <td width="10%">断裂特征</td>
              <td width="10%">断裂位置(mm)</td>
              <td width="10%">结果判定</td>
            </tr>
            <tr height="40">
              <td><el-input type="text" v-model="form.shijbh1" disabled /></td>
              <td rowspan="3"><el-input type="text" v-model="form.zhij1" disabled /></td>
              <td rowspan="3"><el-input type="text" v-model="form.jiemj1" disabled /></td>
              <td>
                <!-- <el-input type="text" v-model="form.jiszb1" /> -->
                <el-input type="text" v-model="form.jiszb1" class="mark" @dblclick.native="showBsJudgeBaseEditView(0)" readonly />
              </td>
              <td><el-input type="text" v-model="form.qiangdscz1" disabled /></td>
              <td><el-input type="text" v-model="form.daunltz1" disabled /></td>
              <td><el-input type="text" v-model="form.duanlwz1" disabled /></td>
              <td><el-input type="text" v-model="form.jiegpd1" disabled /></td>
            </tr>
            <tr height="40">
              <td><el-input type="text" v-model="form.shijbh2" disabled /></td>
              <td>
                <!-- <el-input type="text" v-model="form.jiszb2" /> -->
                <el-input type="text" v-model="form.jiszb2" class="mark" @dblclick.native="showBsJudgeBaseEditView(1)" readonly />
              </td>
              <td><el-input type="text" v-model="form.qiangdscz2" disabled /></td>
              <td><el-input type="text" v-model="form.daunltz2" disabled /></td>
              <td><el-input type="text" v-model="form.duanlwz2" disabled /></td>
              <td><el-input type="text" v-model="form.jiegpd2" disabled /></td>
            </tr>
            <tr height="40">
              <td><el-input type="text" v-model="form.shijbh3" disabled /></td>
              <td>
                <!-- <el-input type="text" v-model="form.jiszb3" /> -->
                <el-input type="text" v-model="form.jiszb3" class="mark" @dblclick.native="showBsJudgeBaseEditView(2)" readonly />
              </td>
              <td><el-input type="text" v-model="form.qiangdscz3" disabled /></td>
              <td><el-input type="text" v-model="form.daunltz3" disabled /></td>
              <td><el-input type="text" v-model="form.duanlwz3" disabled /></td>
              <td><el-input type="text" v-model="form.jiegpd3" disabled /></td>
            </tr>
            <tr height="40">
              <td><el-input type="text" v-model="form.shijbh4" disabled /></td>
              <td rowspan="3"><el-input type="text" v-model="form.zhij4" disabled /></td>
              <td rowspan="3"><el-input type="text" v-model="form.jiemj4" disabled /></td>
              <td>
                <!-- <el-input type="text" v-model="form.jiszb4" /> -->
                <el-input type="text" v-model="form.jiszb4" class="mark" @dblclick.native="showBsJudgeBaseEditView(3)" readonly />
              </td>
              <td><el-input type="text" v-model="form.qiangdscz4" disabled /></td>
              <td><el-input type="text" v-model="form.daunltz4" disabled /></td>
              <td><el-input type="text" v-model="form.duanlwz4" disabled /></td>
              <td><el-input type="text" v-model="form.jiegpd4" disabled /></td>
            </tr>
            <tr height="40">
              <td><el-input type="text" v-model="form.shijbh5" disabled /></td>
              <td>
                <!-- <el-input type="text" v-model="form.jiszb5" /> -->
                <el-input type="text" v-model="form.jiszb5" class="mark" @dblclick.native="showBsJudgeBaseEditView(4)" readonly />
              </td>
              <td><el-input type="text" v-model="form.qiangdscz5" disabled /></td>
              <td><el-input type="text" v-model="form.daunltz5" disabled /></td>
              <td><el-input type="text" v-model="form.duanlwz5" disabled /></td>
              <td><el-input type="text" v-model="form.jiegpd5" disabled /></td>
            </tr>
            <tr height="40">
              <td><el-input type="text" v-model="form.shijbh6" disabled /></td>
              <td>
                <!-- <el-input type="text" v-model="form.jiszb6" /> -->
                <el-input type="text" v-model="form.jiszb6" class="mark" @dblclick.native="showBsJudgeBaseEditView(5)" readonly />
              </td>
              <td><el-input type="text" v-model="form.qiangdscz6" disabled /></td>
              <td><el-input type="text" v-model="form.daunltz6" disabled /></td>
              <td><el-input type="text" v-model="form.duanlwz6" disabled /></td>
              <td><el-input type="text" v-model="form.jiegpd6" disabled /></td>
            </tr>
            <tr height="40">
              <td><el-input type="text" v-model="form.shijbh7" disabled /></td>
              <td rowspan="3"><el-input type="text" v-model="form.zhij7" disabled /></td>
              <td rowspan="3"><el-input type="text" v-model="form.jiemj7" disabled /></td>
              <td>
                <!-- <el-input type="text" v-model="form.jiszb7" /> -->
                <el-input type="text" v-model="form.jiszb7" class="mark" @dblclick.native="showBsJudgeBaseEditView(6)" readonly />
              </td>
              <td><el-input type="text" v-model="form.qiangdscz7" disabled /></td>
              <td><el-input type="text" v-model="form.daunltz7" disabled /></td>
              <td><el-input type="text" v-model="form.duanlwz7" disabled /></td>
              <td><el-input type="text" v-model="form.jiegpd7" disabled /></td>
            </tr>
            <tr height="40">
              <td><el-input type="text" v-model="form.shijbh8" disabled /></td>
              <td>
                <!-- <el-input type="text" v-model="form.jiszb8" /> -->
                <el-input type="text" v-model="form.jiszb8" class="mark" @dblclick.native="showBsJudgeBaseEditView(7)" readonly />
              </td>
              <td><el-input type="text" v-model="form.qiangdscz8" disabled /></td>
              <td><el-input type="text" v-model="form.daunltz8" disabled /></td>
              <td><el-input type="text" v-model="form.duanlwz8" disabled /></td>
              <td><el-input type="text" v-model="form.jiegpd8" disabled /></td>
            </tr>
            <tr height="40">
              <td><el-input type="text" v-model="form.shijbh9" disabled /></td>
              <td>
                <!-- <el-input type="text" v-model="form.jiszb9" /> -->
                <el-input type="text" v-model="form.jiszb9" class="mark" @dblclick.native="showBsJudgeBaseEditView(8)" readonly />
              </td>
              <td><el-input type="text" v-model="form.qiangdscz9" disabled /></td>
              <td><el-input type="text" v-model="form.daunltz9" disabled /></td>
              <td><el-input type="text" v-model="form.duanlwz9" disabled /></td>
              <td><el-input type="text" v-model="form.jiegpd9" disabled /></td>
            </tr>
            <tr>
              <td colspan="8" height="30px">
                <span v-if="isPdf" class="textarea-span">{{ form.jiancjl }}</span>
                <el-input v-else type="textarea" :rows="2" v-model="form.jiancjl" @focus="handleFocus('jiancjl')" @dblclick.native="getJcjl()" />
              </td>
            </tr>
          </tbody>
        </table>
        <!------------------------------附加声明-------------------------->
        <table height="30px" class="bottom-table">
          <tr>
            <td>
              <span v-if="isPdf" class="textarea-span">{{ form.fujsm }}</span>
              <el-input v-else type="textarea" :rows="2" v-model="form.fujsm" @focus="handleFocus('fujsm')" />
            </td>
          </tr>
        </table>
      </div>
      <!------------------------------表底-------------------------->
      <table height="22px" class="transparent">
        <tbody>
        <tr>
          <td width="10%" align="right">检测：</td>
          <td width="15%" align="left"></td>
          <td width="10%" align="right">审核：</td>
          <td width="15%" align="left"></td>
          <td width="10%" align="right">批准：</td>
          <td align="left" width="15%"></td>
          <td width="10%">日期：</td>
          <td align="left" width="15%"></td>
        </tr>
        </tbody>
      </table>
    </div>
    <bs-instrument-view ref="bsInstrumentViewRef" @select="selectInstrument"></bs-instrument-view>
    <bs-jiancyj-view ref="bsJiancyjViewRef" @select="selectJiancyj" :syType="syType"></bs-jiancyj-view>
    <bs-judge-base-view ref="bsJudgeBaseViewRef" @select="selectJudge" :syType="syType"></bs-judge-base-view>
    <bs-judge-base-edit-view ref="bsJudgeBaseEditViewRef" @submit="selectJudgeBaseEdit" :syType="syType"></bs-judge-base-edit-view>
  </div>
</template>

<script>
import { listGcjxljjtbgBsInfo, getGcjxljjtbgBsInfo, delGcjxljjtbgBsInfo, addGcjxljjtbgBsInfo, updateGcjxljjtbgBsInfo, queryJcjl } from "@/api/report_gc/gcjxljjtbgBsInfo";
import BsInstrumentView from "@/views/dept/bsInstrument/BsInstrumentView.vue";
import BsJudgeBaseEditView from "@/views/sycs/bsJudgeBase/BsJudgeBaseEditView.vue";

import decimal from "@/utils/big-decimal";
import BsJiancyjView from "@/views/sycs/bsJiancyj/BsJiancyjView";
import BsJudgeBaseView from "@/views/sycs/bsJudgeBase/BsJudgeBaseView";
import { emptyConvert, handleFocus, uniqueStr } from "@/views/reportForms/utils";
import { computeBiQualification } from "@/api/sycs/biQualification";
import Bus from "@/utils/bus";

export default {
  name: "gcjxljjtbg",
  components: {
    BsInstrumentView,
    BsJiancyjView,
    BsJudgeBaseView,
    BsJudgeBaseEditView
  },
  props: {
    excelId: {
      type: [String, Number],
      default: () => ""
    },
    syType: {
      type: [String, Number],
      default: () => ""
    },
    page: {
      type: Number,
      default: () => 0
    },
    isPdf: {
      type: Boolean,
      default: () => false
    }
  },
  data() {
    return {
      activeKey: null,
      params: {},
      query: {},
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        excelId: [{ required: true, message: "主键不能为空", trigger: "blur" }]
      }
    };
  },
  watch: {
    isPdf(newVal, oldVal) {
      this.form = { ...emptyConvert(this.form, newVal) };
    }
  },
  created() {
    this.getInfo();
  },
  mounted() {
    Bus.$on("setGcJxljjtForm", (data) => {
      console.log(this.form,'1');
      console.log(data,'2');
      
      this.form = { ...this.form, ...data, excelId: this.excelId || this.$defaultExcelId };
      // for (let index = 1; index <= 9; index++) {
      //   this.form["jiszb" + index] = null;
      // }
    }),
      // 检测依据
      Bus.$on("setGcjxljjtBgJiancyj", (data) => {
        const { jiancyj, jiancyjIds } = data;
        const str = jiancyj + (this.form.jiancyj ? "、" + this.form.jiancyj : "");
        const ids = jiancyjIds + (this.form.jiancyjIds ? "," + this.form.jiancyjIds : "");
        this.form.jiancyj = uniqueStr(str, "、");
        this.form.jiancyjIds = uniqueStr(ids, ",");
      });
    // 主要设备
    Bus.$on("setGcjxljjtBgZhuyyqsbmcjbh", (data) => {
      const { zhuyyqsbmcjbh, shebIds } = data;
      const str = zhuyyqsbmcjbh + (this.form.zhuyyqsbmcjbh ? "、" + this.form.zhuyyqsbmcjbh : "");
      const ids = shebIds + (this.form.shebIds ? "," + this.form.shebIds : "");
      this.form.zhuyyqsbmcjbh = uniqueStr(str, "、");
      this.form.shebIds = uniqueStr(ids, ",");
    });
  },
  beforeDestroy() {
    // 或者你可以使用其他合适的生命周期钩子
    // 停止监听事件
    Bus.$off("setGcJxljjtForm");
    Bus.$off("setGcjxljjtBgJiancyj");
    Bus.$off("setGcjxljjtBgZhuyyqsbmcjbh");
  },
  methods: {
    // 获取详情
    getInfo() {
      getGcjxljjtbgBsInfo(this.excelId || this.$defaultExcelId).then((response) => {
        this.form = response.data;
        if (!this.form.jiancjl) {
          this.form.jiancjl = "检测结论：";
        }
        if (!this.form.fujsm) {
          this.form.fujsm = "附加声明：";
        }
      });
    },

    // 显示检测依据列表
    showBsJiancyjView() {
      this.$refs.bsJiancyjViewRef.init(this.form.jiancyjIds);
    },
    // 检测依据选择
    selectJiancyj(info) {
      this.form.jiancyj = info.label;
      this.form.jiancyjIds = info.ids;
    },

    // 显示判定依据列表
    showBsJudgeBaseView() {
      this.$refs.bsJudgeBaseViewRef.init(this.form.pandyjIds);
    },
    // 判断依据选择
    selectJudge(info) {
       this.form.pandyjIds = info.ids;
      this.form.pandyj = info.label;
    },

    // 显示仪器列表
    showBsInstrumentView() {
      this.$refs.bsInstrumentViewRef.init(this.form.shebIds);
    },
    // 仪器选择
    selectInstrument(info) {
      this.form.zhuyyqsbmcjbh = info.label;
      this.form.shebIds = info.ids;
    },

    // 获取检测结论
    getJcjl() {
      const form = JSON.parse(JSON.stringify(this.form));
      queryJcjl(emptyConvert(form)).then((res) => {
        const info = res.data;
        this.form.jiancjl = info.jiancjl;
      });
    },
    handleFocus(event) {
      handleFocus(event, this.page, this.form[event]);
    },
    // 显示单个技术编辑
    showBsJudgeBaseEditView(key) {
      this.activeKey = key;
      const info = this.form.baDetailVos[key];
      info.refQualId = info.qualId;
      this.$refs.bsJudgeBaseEditViewRef.init(info);
    },
    // 编辑单个技术指标后赋值
    selectJudgeBaseEdit(info) {
      if (info.qualId) {
        this.form.baDetailVos[this.activeKey] = info;
      }
      this.computeDetectionResult([this.activeKey]);
    },
    // 计算检测结果
    computeDetectionResult(keys) {
      if (!keys || keys.length <= 0) {
        return;
      }

      const data = keys.map((key) => {
        const info = {
          ...this.form.baDetailVos[key],
          jiancjg: this.form.baDetailVos[key].jiancjg == "-" ? "" : this.form["qiangdscz" + (key + 1)]
        };
        return info;
      });
      computeBiQualification(data).then((res) => {
        const returnData = res.data;
        returnData.forEach((item) => {
          item.jiancjg = item.jiancjg ? item.jiancjg : "-";
          // this.form.baDetailVos[item.qualId] = item;
          this.form["jiszb" + (this.activeKey + 1)] = item.jiszb;
          this.form["jiegpd" + (this.activeKey + 1)] = item.jiegpd;
        });
      });
    },
    submitForm () {
      return this.form;
    },
  }
};
</script>


<style scoped>
</style>
